package com.hand.demo.app.service.impl;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.hand.demo.app.service.HhrTaProjExpService;
import org.springframework.stereotype.Service;
import com.hand.demo.domain.entity.HhrTaProjExp;
import com.hand.demo.domain.repository.HhrTaProjExpRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 项目经历表(HhrTaProjExp)应用服务
 *
 * @author
 * @since 2025-06-16 12:16:52
 */
@Service
public class HhrTaProjExpServiceImpl implements HhrTaProjExpService {
    @Autowired
    private HhrTaProjExpRepository hhrTaProjExpRepository;

    @Override
    public Page<HhrTaProjExp> selectList(PageRequest pageRequest, HhrTaProjExp hhrTaProjExp) {
        return PageHelper.doPageAndSort(pageRequest, () -> hhrTaProjExpRepository.selectList(hhrTaProjExp));
    }

    @Override
    public void saveData(List<HhrTaProjExp> hhrTaProjExps) {
        List<HhrTaProjExp> insertList = hhrTaProjExps.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<HhrTaProjExp> updateList = hhrTaProjExps.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        hhrTaProjExpRepository.batchInsertSelective(insertList);
        hhrTaProjExpRepository.batchUpdateByPrimaryKeySelective(updateList);
    }

    @Override
    public void deleteByResumeId(Long resumeId) {
        HhrTaProjExp query = new HhrTaProjExp();
        query.setResumeId(resumeId);
        List<HhrTaProjExp> existingList = hhrTaProjExpRepository.selectList(query);
        if (!existingList.isEmpty()) {
            hhrTaProjExpRepository.batchDeleteByPrimaryKey(existingList);
        }
    }
}

